<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="JavaServlet.TimeServlet.Banji"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>   
 	<%
     	List<Banji> list = (ArrayList<Banji>)request.getAttribute("list" );
     %>
	<form id="ajax_form" method = "post" onsubmit="return false"> 
		 用户名：<input type="text" name="name"><br/>
		年龄：<input type="text" name="age"><br/>
		性别：<input type="text" name="gender"><br/>
		班级: <select name="banjiId">
				<option>--请选择--</option>
				<%
					for (Banji banji : list) {
	 				%> 	
						<option value="<%=banji.getId()%>"><%=banji.getName()%></option>
				<%
					} 
	 				%> 	
			</select><br/>
		<input type="button" onclick="submitForm()" value="添加" class="btn btn-info">
	</form>  
	<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/layer/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/layer/layer/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/layer/layer/util.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function submitForm(){
				$.ajax({
					url : "${pageContext.request.contextPath}/student?method=insert",
					type : "post",
					dataType : "json",
					data : $("#ajax_form").serialize(),
					success : function(jsonObj){
						console.log(jsonObj);
						if(jsonObj.code == util.SUCCESS){
							mylayer.successMsg(jsonObj.msg);
							//当你在iframe页面关闭自身时
							var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
							setTimeout(function(){
								parent.layer.close(index); //再执行关闭 
								// 刷新父页面
								window.parent.location.reload();
							},1000);
						}else{
							mylayer.errorMsg(jsonObj.msg);
						}
					}
				});
			}
		</script>
</body>
</html>